package com.yuncheng.oaApi.controller;

import java.util.*;
import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.entity.OaSpcyJcyFybxdgrjl;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.oaApi.service.IOaSpcyJcyFybxdgrjlService;
import com.yuncheng.oaApi.utils.GetUuIdUtils;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.oaApi.entity.NkRsBxqtzyjl;
import com.yuncheng.oaApi.service.INkRsBxqtzyjlService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;

/**
 * @Description: 内控_报销其他摘要记录
 * @Author: yuncheng
 * @Date: 2024-05-16
 * @Version: V1.0
 */
@Api(tags = "内控_报销其他摘要记录接口")
@RestController
@RequestMapping("/api/spzx-oa/nkRsBxqtzyjl")
public class NkRsBxqtzyjlController extends BaseController<NkRsBxqtzyjl, INkRsBxqtzyjlService> {

    private static final Logger log = LoggerFactory.getLogger(NkRsBxqtzyjlController.class);

    @Resource
    private INkRsBxqtzyjlService nkRsBxqtzyjlService;

    @Resource
    @Lazy
    private IOaSpcyJcyFybxdgrjlService spcyJcyFybxdgrjlService;


    @AutoLog(value = "nkRsBxqtzyjl-分页列表查询")
    @ApiOperation(value = "nkRsBxqtzyjl-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(NkRsBxqtzyjl nkRsBxqtzyjl, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        if (StringUtils.isBlank(nkRsBxqtzyjl.getFbxdid())){
            throw new BusinessException("报销单id不能为空");
        }
        LambdaQueryWrapper<NkRsBxqtzyjl> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(StringUtils.isNotBlank(nkRsBxqtzyjl.getFbxdid()),NkRsBxqtzyjl ::getFbxdid, nkRsBxqtzyjl.getFbxdid());
        Page<NkRsBxqtzyjl> page = new Page<>(pageNo, pageSize);
        IPage<NkRsBxqtzyjl> pageList = nkRsBxqtzyjlService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }



    /**
     * 添加
     *
     * @param nkRsBxqtzyjl
     * @return
     */
    @AutoLog(value = "内控_报销其他摘要记录-添加")
    @ApiOperation(value = "内控_报销其他摘要记录-添加")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody NkRsBxqtzyjl nkRsBxqtzyjl) {
        HttpResult<String> result = new HttpResult(true);
        nkRsBxqtzyjl.setId(GetUuIdUtils.ReplaceUuId());
        if (StringUtils.isBlank(nkRsBxqtzyjl.getFbxdid())){
            throw new BusinessException("报销单id不能为空");
        }

        if (StringUtils.isBlank(nkRsBxqtzyjl.getFbxdgrjl())){
            throw new BusinessException("报销单个人id不能为空");
        }else {
            OaSpcyJcyFybxdgrjl jcyFybxdgrjl = spcyJcyFybxdgrjlService.getById(nkRsBxqtzyjl.getFbxdgrjl());
            nkRsBxqtzyjl.setFbxrxm(jcyFybxdgrjl.getRealname());
            nkRsBxqtzyjl.setFbxrid(jcyFybxdgrjl.getFuserid());
        }




        if (StringUtils.isBlank(nkRsBxqtzyjl.getFsfgwkfk())){
            nkRsBxqtzyjl.setFsfgwkfk(OaCommonFlowConstant.SFGWKFK_NO);
        }



        nkRsBxqtzyjlService.save(nkRsBxqtzyjl);
        result.setResult(nkRsBxqtzyjl.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }

    /**
     * 编辑
     *
     * @param nkRsBxqtzyjl
     * @return
     */
    @AutoLog(value = "内控_报销其他摘要记录-编辑")
    @ApiOperation(value = "内控_报销其他摘要记录-编辑")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody NkRsBxqtzyjl nkRsBxqtzyjl) {
        nkRsBxqtzyjlService.updateById(nkRsBxqtzyjl);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "内控_报销其他摘要记录-通过id删除")
    @ApiOperation(value = "内控_报销其他摘要记录-通过id删除")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        nkRsBxqtzyjlService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "内控_报销其他摘要记录-批量删除")
    @ApiOperation(value = "内控_报销其他摘要记录-批量删除")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        nkRsBxqtzyjlService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "内控_报销其他摘要记录-通过id查询")
    @ApiOperation(value = "内控_报销其他摘要记录-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        NkRsBxqtzyjl nkRsBxqtzyjl = nkRsBxqtzyjlService.getById(id);
        return HttpResult.ok(nkRsBxqtzyjl);
    }


    /**
     * 数据转换
     * @param nkRsBxqtzyjl
     */
    private void formatValue(NkRsBxqtzyjl nkRsBxqtzyjl){
    }

}
